<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <jsp:include page="../include.jsp" flush="true"/>
	<script type="text/javascript">
	var grid;
	var win;
	var url;
	$(function(){
		if(user_role != 1 && user_role != 5){
			$("#query-form").hide();
		}
	})
	$(function() {
		grid = $('#user_info').datagrid();
		$('#btn-save,#btn-cancel').linkbutton();
		win = $('#user-window').window( {
			collapsible : false,//折叠
			minimizable : false,//最小化
			maximizable : false,//最大化
			draggable : true,//拖动
			resizable : false,//改变大小
			modal : true,
			closed : true
		});
	});

	function append() {
		reject();
		$('#plan_week').attr({onblur:"checkPlanWeek()",disabled:false});
		win.window('open');
		status = 'enable';
		$('#userform').form('clear');
		url ='c03!addPlan?plan_stu_id='+user_id;
	}
	function remove() {
		var rows = $('#table_foot').datagrid('getSelected');
		if(!rows){
			show('请先选择一行数据!');
			return false;
		}
		$.messager.confirm('提示','确定要删除吗?',function(result){  
            if (result){  
                $.post('c03!removePlan?plan_id='+rows.plan_id,function(message){  
                    $('#table_foot').datagrid('reload');
                });
            } 
            reject();
        });
	}
	function update() {
		$('p').remove();
		var row = $('#table_foot').datagrid('getSelected');
		if (row) {
			$('#plan_week').attr({onblur:"",disabled:'disabled'});
			win.window('open');
			$('#userform').form('clear');
			$('#userform').form('load', row);
			url = 'c03!updatePlan';
		} else {
			show('请先选择一行数据!');
		}
	}
	function save() {
		$('#userform').form('submit', {
			url : url,
			onSubmit : function() {
				return $(this).form('validate');
			},
			success : function(data) {
				$('#table_foot').datagrid('reload');
				//$('#table_body').datagrid('reload');
				$('p').remove();
				win.window('close');
			}
		});
	}
	function updateMission(){
		var row = $('#table_body').datagrid('getSelected');
		if (row) {
			$.messager.prompt('任务分配明细', '请给 '+row.USER_NAME+' 分配任务', function(r){
				if (r){
					$.post('c03!updateMission',
						{stu_id:row.STU_ID, stu_mission:r},
						function(message){  
	                    	$('#table_body').datagrid('reload');
	                    	show(message.returnMsg);
	                    }
                    );
				}
			});
		} else {
			show('请先选择一行数据!');
		}
	}
	function query(){
		var params = $('#user_info').datagrid('options').queryParams; //先取得 datagrid 的查询参数  
        var fields =$('#query-form').serializeArray(); //自动序列化表单元素为JSON对象  
        $.each( fields, function(i, field){
            params[field.name] = field.value; //设置查询参数  
        });   
        $('#user_info').datagrid('reload'); //设置好查询参数 reload 一下就可以了
	}
	function reject(){
		$('#table_body').datagrid('clearSelections');
		$('#table_foot').datagrid('clearSelections');
	} 
	
	function closeWindow() {
		win.window('close');
		reject();
	}
</script>
	<script type="text/javascript">
		$(function(){
			var lastIndex;
			$('#user_info').datagrid({
				width:'auto',
				height:'auto',
				method:'post',
				nowrap: false,
				fitColumns:'true',
				fit:true,
				striped: true,
				url:'c03!queryPlanHead?user_role_id='+<%=session.getAttribute("user_role_id")%>+'&user_id='+<%=session.getAttribute("user_id")%>,
				showFooter: true,
				idField:'STU_ID',
				columns:[[
					{field:'STU_ID',title:'学号',align:'center',width:80},
					{field:'USER_NAME',title:'姓名',align:'center',width:60},
					{field:'STU_GRADE',title:'年级',align:'center',editor:'text',width:40},
					{field:'STU_CLASS',title:'班级',align:'center',editor:'text',width:40},
					{field:'FACULTY_NAME',title:'专业',align:'center',editor:'text',width:120},
					{field:'MAJOR_NAME',title:'学院',align:'center',editor:'text',width:120},
					{field:'GROUP_NAME',title:'组名',align:'center',editor:'text',width:170},
					{field:'TASK_NAME',title:'课题名',align:'center',editor:'text',width:170}
				]],
				rownumbers:true,
				singleSelect:true,
				onDblClickRow:function(){
					var rows = grid.datagrid('getSelected');
					loadbody(rows.STU_ID);
					loadfoot(rows.STU_ID);
					reject();
				},
				onLoadSuccess:function(){  
               		$('#user_info').datagrid('clearSelections'); 
            	}
			});
		});
		
	</script>
  </head>
  <body>
  	<div class="easyui-layout" data-options="fit:true">
		<div data-options="region:'north',split:false,border:false" title="" style="height:40px">
			<form id="query-form" method="post" style="padding-left:5px;">
		  		课题名<input type="text" class="easyui-validatebox" name="taskId" style="width:90px;">&nbsp;
		  		小组名<input type="text" class="easyui-validatebox" name="groupName" style="width:90px;"></input>&nbsp;
				学号<input type="text" class="easyui-validatebox" name="stuId" style="width:90px;"></input>&nbsp;
				姓名<input type="text" class="easyui-validatebox" name="stuName" style="width:90px;"></input>&nbsp;
				所属专业<input class="easyui-combobox" name="majorId" style="width:90px;"
										data-options="
												url:'c01!queryMajor',
												mode:'remote',
												valueField:'MAJOR_ID',
												textField:'MAJOR_NAME',
												panelHeight:'auto'
									">&nbsp;
				所属学院<input class="easyui-combobox" name="facultyId" style="width:90px;"
										data-options="
												url:'c01!queryFaculty',
												mode:'remote',
												valueField:'FACULTY_ID',
												textField:'FACULTY_NAME',
												panelHeight:'auto'
									">&nbsp;&nbsp;
		        <a href="javascript:void(0)" onclick="query()" id="btn-save" icon="icon-search">查询</a>
		  	</form>
		</div>
		<div data-options="region:'center',border:false">
			<div class="easyui-layout" data-options="fit:true">
				<div data-options="region:'center',split:false,border:false" title="小组计划表头信息">
					<table id="user_info"></table>
					<div id="user-window" title="用户窗口" style="width:450px;height:auto;">
						<div style="padding:20px 20px 40px 80px;">
							<form id="userform" method="post" >
								<table>
									<tr>
										<td>
											<input type="hidden" name="plan_stu_id" id="plan_stu_id" class="easyui-validatebox">
				        				</td>
										<td>
				        				</td>
									</tr>
									<tr>
										<td>计划周：</td>
										<td>
											<input name="plan_week" id="plan_week" class="easyui-numberspinner" style="width:130px;"  
				        						required="required" data-options="min:1,max:25,editable:true" onblur="checkPlanWeek()">
						        				<script type="text/javascript">
						        					function checkPlanWeek(){
						        						$.post('c03!checkAddPlan',
						        							{stu_id:user_id, plan_week:$('#plan_week').val()},
						        							function(message){
						        								if(message.returnFlag == 'N'){
						        									$("p").remove();
																	$("#check1").append("<p style='color:red'>"+message.returnMsg+"</p>");
																	$('#plan_week').focus();
						        								}else{
						        									$("p").remove();
						        								}
						        							}
						        						);
						        					}
						        				</script>
				        				</td>
				        				<td><input type="hidden" name="plan_id" id="plan_id" class="easyui-validatebox" ></td>
		        						<td id="check1"></td>
									</tr>
									<tr>
										<td>预计完成：</td>
										<td><input type="text" class="easyui-validatebox" name="plan_expect" id="plan_expect" required="true"></input></td>
									</tr>
									<tr>
										<td>实际完成：</td>
										<td><input type="text" class="easyui-validatebox" name="plan_done" id="plan_done"></input></td>
									</tr>
									<tr>
										<td>参与度：</td>
										<td>
											<select id="plan_attendance" class="easyui-combobox" name="plan_attendance" style="width:130px;" data-options="panelHeight:'auto'">
												<option value="非常积极">非常积极</option>
												<option value="积极">积极</option>
												<option value="一般">一般</option>
												<option value="很少">很少</option>
												<option value="完全没有">完全没有</option>
											</select>
										</td>
									</tr>
									<tr>
										<td>贡献度：</td>
										<td>
											<select id="plan_contribution" class="easyui-combobox" name="plan_contribution" style="width:130px;" data-options="panelHeight:'auto'">
												<option value="非常高">非常高</option>
												<option value="高">高</option>
												<option value="一般">一般</option>
												<option value="很少">很少</option>
												<option value="完全没有">完全没有</option>
											</select>
										</td>
									</tr>
									<tr>
										<td>备注：</td>
										<td>
											<textarea name="plan_note" id="plan_note" class="easyui-validatebox"></textarea>
				        				</td>
									</tr>
								</table>
							</form>
						</div>
						<div style="text-align:center;padding:5px;">
							<a href="javascript:void(0)" onclick="save()" id="btn-save" icon="icon-save">确认</a>
							<a href="javascript:void(0)" class="easyui-linkbutton" onclick="closeWindow()" id="btn-cancel" icon="icon-cancel">取消</a>
						</div>
					</div>
				</div>
				<div data-options="region:'south',split:true,border:false" title="小组成员" style="height:150px">
					<table id="table_body"></table>
				</div>
			</div>
		</div>
		<div data-options="region:'south',split:true,border:false" title="计划列表" style="height:150px">
			<table id="table_foot"></table>
		</div>
	</div>
	
	<script type="text/javascript" src="./jquery-easyui-1.3.2/easyloader.js"></script>
	<script type="text/javascript">
		function loadbody(stu_id){
			using('datagrid', function(){
				$('#table_body').datagrid({
					width:'auto',
					height:'auto',
					method:'post',
					toolbar:toolbarbody,
					nowrap: false,
					fitColumns:'true',
					fit:true,
					striped: true,
					url:'c03!queryPlanBody?stu_id='+stu_id,
					showFooter: true,
					idField:'STU_ID',
					columns:[[
						{field:'STU_ID',title:'学号',align:'center',width:120},
						{field:'USER_NAME',title:'姓名',align:'center',width:120},
						{field:'STU_PHONE',title:'电话',align:'center',width:120},
						{field:'STU_QQ',title:'QQ',align:'center',editor:'text',width:40},
						{field:'STU_EAMIL',title:'邮箱',align:'center',editor:'text',width:120},
						{field:'STU_NOTE',title:'备注',align:'center',editor:'text',width:80},
						{field:'STU_MISSION',title:'个人任务',align:'center',editor:'text',width:120}
					]],
					rownumbers:true,
					singleSelect:true
				});
			});
		}
		
		function loadfoot(stu_id){
			using('datagrid', function(){
				$('#table_foot').datagrid({
					width:'auto',
					height:'auto',
					method:'post',
					toolbar:toolbarfoot,
					nowrap: false,
					fitColumns:'true',
					fit:true,
					striped: true,
					url:'c03!queryPlanFoot?stu_id='+stu_id,
					showFooter: true,
					idField:'plan_id',
					columns:[[
						{field:'ck',checkbox:true,width:2}, //显示复选框
						{field:'plan_id',title:'小组计划主键',align:'center',width:20,hidden:true},
						{field:'plan_stu_id',title:'学号',align:'center',width:40},
						{field:'plan_week',title:'周次',align:'center',editor:'text',width:40},
						{field:'plan_expect',title:'预计完成',align:'center',editor:'text',width:120},
						{field:'plan_done',title:'实际完成',align:'center',editor:'text',width:120},
						{field:'plan_cre_time',title:'最后更新',align:'center',editor:'text',width:80},
						{field:'plan_attendance',title:'参与度',align:'center',editor:'text',width:80},
						{field:'plan_contribution',title:'贡献度',align:'center',editor:'text',width:80},
						{field:'plan_note',title:'备注',align:'center',editor:'text',width:120}
					]],
					rownumbers:true,
					singleSelect:true
				});
			});
		}
		
		if(user_role_id != 3 && user_role_id != 6){
			var toolbarbody = [];
			var toolbarfoot = []
		}else{
			var toolbarbody=[{
				text:'分配任务',
				iconCls:'icon-edit',
				handler:function(){updateMission()}
			}];
			var toolbarfoot = [{
				text:'增加',
				iconCls:'icon-add',
				handler:function(){append()}
			},{
				text:'修改',
				iconCls:'icon-edit',
				handler:function(){update()}
			},{
				text:'删除',
				iconCls:'icon-cut',
				handler:function(){remove()}
			},{
				text:'返回',
				iconCls:'icon-undo',
				handler:function(){reject()}
			}];
		}
	</script>
  </body>
</html>
